//立即执行函数
var  a=2;
(function foo() {
    var a=3
    console.log(a)//3
})()
console.log(a)//2


//IIFE
var a=2;
(function IIFE() {
    var a=3
    console.log(a)//3
})()
console.log(a)//2


//进阶用法
var a =2;
(function IIFE(global) {
    vara=3;
    console.log(a)//3
    console.log(global.a)//2
})(windows)
console.log(a)//2
//解决underfind存在

underfind=true;
(function IIFE(underfind) {
    var a;
    if(a===underfind){
        console.log("underfind is safe here")
    }  
})()

//UMD
var a=2;
(function IIFE(def) {
    def(windows)
})(function def(global) {
    var a=3;
    console.log(a)//3
    console.log(global.a)//2
})